package com.pay.utils.validate.vali_util;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * 工具类
 *
 * @author MENG
 * @version 2018/7/11
 * @see
 */
public class ValidateUtil
{
    /**
     * 检查Email 是否合法
     * @param email
     * @return
     */
    public static boolean checkEmail(String email)
    {
        String regex = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$";

        Pattern p = Pattern.compile(regex);

        Matcher m = p.matcher(email);

        return m.matches();
    }

    /**
     * 检查phone 是否合法
     * @param phone
     * @return
     */
    public static boolean checkPhone(String phone)
    {
        String regex = "^1[3|4|5|7|8][0-9]{9}$";

        Pattern p = Pattern.compile(regex);

        Matcher m = p.matcher(phone);

        return m.matches();
    }

    /**
     * 返会 成功
     *
     * @return
     */
    public static Map<String,Object> returnSuccess(Object data)
    {
        Map<String, Object> resultMap = new HashMap<>(4);

        resultMap.put(ValidateConstants.RESULT_CODE, ValidateCodeEnum.SUCCESS.getCode());

        resultMap.put(ValidateConstants.RESULT_MSG, ValidateCodeEnum.SUCCESS.getMessage());

        resultMap.put(ValidateConstants.RESULT_DATA, data);

        return resultMap;
    }

    /**
     * 返会 错误
     *
     * @return
     */
    public static Map<String,Object> returnError(String code,String message)
    {
        Map<String, Object> resultMap = new HashMap<>(4);

        resultMap.put(ValidateConstants.RESULT_CODE, code);

        resultMap.put(ValidateConstants.RESULT_MSG, message);

        return resultMap;
    }


    /**
     * 返会 错误
     *
     * @return
     */
    public static Map<String,Object> returnError(ValidateCodeEnum ValidateCodeEnum)
    {
        Map<String, Object> resultMap = new HashMap<>(4);

        resultMap.put(ValidateConstants.RESULT_CODE, ValidateCodeEnum.getCode());

        resultMap.put(ValidateConstants.RESULT_MSG, ValidateCodeEnum.getMessage());

        return resultMap;
    }

    /**
     * 返会 成功
     *
     * @return
     */
    public static Map<String,Object> returnSuccess()
    {
        Map<String, Object> resultMap = new HashMap<>(4);

        resultMap.put(ValidateConstants.RESULT_CODE, ValidateCodeEnum.SUCCESS.getCode());

        resultMap.put(ValidateConstants.RESULT_MSG, ValidateCodeEnum.SUCCESS.getMessage());

        return resultMap;
    }


}
